#include "user_model.h"

User_Model *User_Model::instance = nullptr;

User_Model *User_Model::getInstance()
{
    if(User_Model::instance == nullptr)
        User_Model::instance = new User_Model;
    return User_Model::instance;
}

int User_Model::insertUserData(QString user_account)
{
    QString sql = QString("INSERT INTO user_table(user_account) VALUES ('%1');").arg(user_account);
    int res = SingletonBD::getInstance()->doUpdateInsertDel(sql);
    return res;
}

int User_Model::doSelectUserData(QString user_account)
{
    QString sql = QString("SELECT * FROM user_table WHERE user_account = '%1';").arg(user_account);
    qDebug() << "selectUserByAccount:" << sql;
    char ** qres = nullptr;
    int row=0, col=0;
    //调用查询函数，row==1 有数据， else 登陆失败
    int res = SingletonBD::getInstance()->doSelect(sql, qres, row ,col);
    if(res==0)
    {
        if(row==0)
        {
            return -1;   //无数据
        }
    }
    return 0;   //返回默认值
}

User_Model::User_Model()
{

}
